external image G1y9QlWNbqiinmoyPTbXzXavVp64Z0PqRUWiVFMnDsZmg6syYnuFA93uTrIuZOQdae1pdv3bkeTQj7xQyroS5ccXI4QD-Qk-eCxWaXquoBaA2CScpW-WZWjYFK4nsZKcsJCKnqjhrw

Introduction

  • Unity is a game engine developed by Unity Technologies
  • The application has many uses from building games and creating virtual environment
  • Unity supports many different platforms like: PC, Mac, Linux, Android, iOS, PS4, Xbox One, Wii U, Webgl and more



Why Unity? Low Barriers to Entry

  • There's a lare community marketplace
    • with lots of cool free assets
    • and lots of high quality assets
  • It's built on familiar languages
    • UnitScript (Javascript)
    • C#
  • Huge Development Library
    • Physics
    • Networking
    • UI
    • Audio
  • Comes with Free Dev Tools
Screen Shot 2016-03-05 at 1.22.02 PM.png
Screen Shot 2016-03-05 at 1.22.02 PM.png


MonoDevelop: Built-In Code Editor for Unity


  • Unity comes with a code editor called MonoDevelop that syncs with your projects
  • This means you can launch MonoDevelop independently of your Unity application, but not have to worry about updating/syncing anything
  • If you prefer another code editor you can configure Unity to launch that, instead of MonoDevelop (Visual Studios)

MonoDev_StartUp.png
MonoDev_StartUp.png

Visual Studio Community 2015

external image F996ZFxKhJDzqKNlrtF7ls8Rjg0DRUxwLAfo7yahJP991AlBOrqvPZXOpDbIxSss1q7I00vyX2lh9SB7oFEbUHY0b-b80Jw0eWjvbiv17QvrD7LvBDS_os5jLRNVpt2rYLIdpzuS-w

Cost of Unity


  • Free personal edition and pricey professional edition
  • Current licensing rate for indie devleopers or small studios is $75/month
  • Source code available for undisclosed price
  • Professional edition offers discounts in marketplace, analytic tools and team licensing

Building a VIrtual Environment


  • Unity can be used to build both 2D and 3D environments
  • 3D games built on X, Y, Z coordinate system
  • Z+ being forward, X+ to the right and Y+ up

external image EdS3sVVsiwWx2Do_Bbwj4O6r_k1zqP0_ponFsW8-HeM3iQTFnUGu-FBMWnWsSBekuIMVB_zaJE4VxEpf8TgysYtvtrcjya09ma9s3foI7kmm4CBchWmsha4_-GwzNniwlerfsIovXQ


Scenes


  • Scenes contain the objects of your game
  • Can be anything from a menu to a level in your game
  • We build our game environments in scenes

GameObjects


  • Every object in your game is a gameobject
  • Can be anything from a building, to individual walls, crates, barrels, camera, trees and even the player itself
  • Each object has special properties like its position, scale, texture, and more
  • we call these properties components

Components


  • Components are functional pieces of a gameobject
  • Components contain key information like Transform, meshes, physics, scripts, audio, network, etc.

List of active components of a gameobject
List of active components of a gameobject



Prefabs


  • Users store gameobject with all of its components into prefabs (prefabricated object)
  • Contributes to convenience and reusability of a project

Unity UI


external image epS2E2zsu972wKkJ7yFXp0FiJKdC_-CznV9DQFOVPy6eBGeHMXotWPlzfecKZ7UhZ0VN2gzysR6uFv3R0pD59yLMVpW0zEm66iKGoh3gtotfEjuMDnnqkCZvKgpODkBn5SIeg5Yq1A

Important Unity Dev Classes


  • MonoBehaviour
    • standard functions and events that get triggered during gameplay interaction
  • Transform
    • information regarding position, rotation, and scale, for a given game object
    • provides the necessary functions to manipulate that information
  • RigidBody
    • provides properties and functions that handle velocity, force, ass, torque, collision, and other physics-related stuff

MonoBehaviour


  • is the base class that every script in Unity derives from. By inheriting the behavior of this class, the scripts that the developer creates can access the "inner workings" of Unity

  • Update - the function that handles the frame update of the script/object
    • often used for movement, triggering events, and responding to input
    • relies on connections and variables that are created in Start function
  • Start - the function that is calledbefore Update is called for first time
    • used for initialization of variables within the script

Ex_C#_Script.png
Ex_C#_Script.png


Transform


  • Everyobject in a scene has a Transform
  • used to store and manipulate the position, rotation and scale of the object
  • Every Transform can have a parent, which allows you to apply position, rotation and scale hierarchically

Screen Shot 2016-03-07 at 8.22.57 PM.png
Screen Shot 2016-03-07 at 8.22.57 PM.png


RigidBody


  • Adding a RIgidBody component to an object will put its motion under the control of Unity's physics engine
  • The RigidBody class lets you apply forces to the object and control it in a physically realistic way

Networking


  • Interpolation
  • Client-side prediction
    • De-Sync
    • Lockstep
  • Client-Authoritative
  • Local player, client, server, and host

external image yNon4bKC7UyO2tQsrw7-iFcKoJ0JUTgqZqhLb594Xt9rfTnNq_t8tPnd89423yXlXBAUR4nmL7b2mqHmT20dK5n3eDgZzememM0TYFPj94yBBIziQnFg-ksvHcxX8IZWbQCKavB1tnU

Built-in Pieces


  • Network Manager allows you to easily configure the server and networking aspects of your game
    • Online/Offline scene
    • IP/Port
    • Player Spawning
    • Spawnable Prefabs

external image tmGigSRVOs7X9o6_MwDga9kDijZ_8XX2mokmdPT2fjMzEb0fH6WKwp3I3oEhwWInhbXW3qQtrPcD7UhC9h9JxHayQe2-nM-r3lM-POJDQxFsxqXF6-JJNwgC1UNNR3vajBxOYITYpQ

Network Behavior


Extends MonoBehaviour, and must be used whenever you need to work with networking within the script
  • Creating objects
  • Moving objects
  • Producing changes to the world

Enables:
  • Client/server checks
  • running code only on the client or servers

Client/Server Communication


SyncVar: Change on server -> update clients
external image A2l4JnLHQRqwKMufvtp578zl8qC2M5Qz1cN-iV1XJcWbln1Yv2qluST8QaIKRDFKDvdw6B1QUeFJNxt1XYd_GTqAumBhCgzgCeF4OXy1pD1u73oGHgZLfNojacv4gjBO5TdYl0OUAA

Command: Run this code only on server
external image ZGLxHoGqqTsRBc0mlw8cud3Ix5ZDjLamy5_PHjDNA-YY-C-4ElEaRVYN3ULIvV9iU4K4deoTXKNTEObuOurYhIvOl7ptE9xKwNRbgDlgjIEamQEO4KKWzgGzxaqR0ARFssDJf8fcGQ

ClientCallback: Run t his code only on client
external image T9PVjbEVkI2wkRnmX0Eou2l8vTYmxY-0ecuhY_ulAHzUQOuOqSnC6nyeIqMTMExvGY0FvspD6U5aLk_fHbtHmbfNlZRWqihoqIxPrI-XUbQn_Xl3kvKkBZ7Mo2m-srAInZbrY6LfjA


Spawning:
  • instantiating an object onlycreatese the object in the "local" world
  • must use NetworkServer.Spawn to put the bullet on server/clients

external image GNL0OSx2slrSPXrwu7vp02w5i8UQlpBnFHb3rb7SfGp4ZBrtiu6JohuO9PhiUAe5zwbZDdq1IAXhOiFitdwoyRmqo6L76bhHPV4QeSL8eyEY5mgxE57t-H02TNQQ0bRL1t8WqgNmUg

Common Pitfalls


Cameras
  • should only be one active camera at a time
  • multiplayer can mess this up

Control Scripts
  • Remote clients will still receive local input if the script is active

Audio Listener
  • You only want one of these active - local player most likely

Pitfalls Filled In


Camera:
  • Deactivate scene-wide
  • activate the local player's camera

Control Scripts:
  • Enable if local player, deactivate otherwise

AudioListener:
  • Enable if local player, deactivate otherwise

What's Missing?


General Opinion: Built-In options are not suitable for games with a large number of players
  • Hard to control the built-in components, generally just write your own

Physics:
  • Networking physics is a nightmare
    • Requires Client-Side tracking of the last ~2 seconds of past states and input
    • Client-SIde prediction cannot predict movement accurately because of non-deterministic physics -> noticeable inaccuracies in all but the best of systems
    • Server authoritative system can cause huge amounts of recalculation
    • Very nuanced and susceptible to bugs

Future Implementations


Chat Box
  • Being able to have scrollable chat box on the bottom of the screen that all players can communicate with within the server
  • Plenty of legally usable code on line to create, the GUI and communication between different players

Login Menu
  • Creating a login menu, probably storing different accounts with username and passwords in a database

Unity vs. Unreal


  • Quicker start up compared to Unreal
  • Quicker to set a prototype
  • Once you start stretching limits you hit walls on Unity (physics, networking)
  • Some people make Unity then port it into Unreal
  • Unity's animation system is much easier to use than Unreal